<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
	pageEncoding="UTF-8"%>
<%@ page
	import="java.util.*,swimv2gm.bl.util.WorkRequestData,swimv2gm.bl.domain.WorkRequestStatus"%>
<!DOCTYPE html>
<html>
<head>
<title>SWIMv2: Richieste di lavoro</title>
<link rel="stylesheet" type="text/css"
	href="/SWIMv2gm/shared/global.css" />
</head>
<body>
	<div id="header">
		<h1>SWIMv2</h1>
	</div>
	<%@include file="/shared/menu.jsp"%>
	<div id="content">
		<h1>Richieste di lavoro</h1>
		<h2>Ricevute</h2>
		<%
			List<WorkRequestData> received = ((List<WorkRequestData>)request.getAttribute("received"));
			if (received == null || received.size() == 0) {
		%><p class="list message">Nessuna richiesta ricevuta.</p>
		<%
			}
			else {
		%>
		<table class="list">
			<thead>
				<tr>
					<th></th>
					<th>Inviata il</th>
					<th>Mittente</th>
					<th>Stato</th>
				</tr>
			</thead>
			<tbody>
				<%
					for (WorkRequestData wr:received) {
							//id,ts,stato,uid,nome
				%>
				<tr>
					<td><a href="ShowRequest?rid=<%=wr.getId()%>">Mostra
							dettagli</a></td>
					<td><%=wr.getTimestamp()%></td>
					<td>
						<%
							if (wr.getUserId() > 0) {
						%> <a href="/SWIMv2gm/user/Profile?uid=<%=wr.getUserId()%>"><%=wr.getUserName()%></a>
						<%
							}
									else {
						%> <a href="mailto:<%=wr.getUserName()%>"><%=wr.getUserName()%></a>
						<%
							}
						%>
					</td>
					<td>
						<%
							if (wr.getStato() == WorkRequestStatus.PENDING) {
						%><span class="pending">In attesa</span> <%
 	}
 			else if (wr.getStato() == WorkRequestStatus.ACCEPTED) {
 %><span class="accept">Accettata</span> <%
 	}
 			else if (wr.getStato() == WorkRequestStatus.DECLINED) {
 %><span class="decline">Rifiutata</span> <%
 	}
 %>
					</td>

				</tr>
				<%
					}
				%>
			</tbody>
		</table>
		<%
			}
		%>

		<h2>Inviate</h2>

		<%
			List<WorkRequestData> sent = ((List<WorkRequestData>)request.getAttribute("sent"));
			if (sent == null || sent.size() == 0) {
		%><p class="list message">Nessuna richiesta inviata.</p>
		<%
			}
			else {
		%>
		<table class="list">
			<thead>
				<tr>
					<th></th>
					<th>Inviata il</th>
					<th>Destinatario</th>
					<th>Stato</th>
				</tr>
			</thead>
			<tbody>
				<%
					for (WorkRequestData wr:sent) {
				%>
				<tr>
					<td><a href="ShowRequest?rid=<%=wr.getId()%>">Mostra
							dettagli</a></td>
					<td><%=wr.getTimestamp()%></td>
					<td><a href="/SWIMv2gm/user/Profile?uid=<%=wr.getUserId()%>"><%=wr.getUserName()%></a></td>
					<td>
						<%
							if (wr.getStato() == WorkRequestStatus.PENDING) {
						%><span class="pending">In attesa</span> <%
 	}
 			else if (wr.getStato() == WorkRequestStatus.ACCEPTED) {
 %><span class="accept">Accettata</span> <%
 	}
 			else if (wr.getStato() == WorkRequestStatus.DECLINED) {
 %><span class="decline">Rifiutata</span> <%
 	}
 %>
					</td>

				</tr>
				<%
					}
				%>
			</tbody>
		</table>
		<%
			}
		%>
	</div>
</body>
</html>